using System;
using System.Text;
using Com.ContentRendering.Api.ParserEngine.State;
using Com.ContentRendering.Api.ParserEngine.Exceptions;

namespace Com.ContentRendering.Api.ParserEngine
{
    /// <summary/>
    public class DocumentParser
    {
        private AbstractState _state;
        private SpecialCharactersInterface _specialCharacters;

        /// <summary/>
        public DocumentParser(SpecialCharactersInterface specialCharacters)
        {
            this._specialCharacters = specialCharacters;
        }

        /// <summary/>
        internal AbstractState State
        {
            set { _state = value; }
        }

        /// <summary/>
        internal SpecialCharactersInterface SpecialCharacters
        {
            get { return this._specialCharacters; }
        }

        /// <summary/>
        public void Parse(
            string document,
            OutputNodeInterface outputNode)
        {
            // set the default state
            this._state = new ContentState(
                this,
                outputNode);

            // inspect each character
            foreach (char value in document)
            {
                this._state.Parse(value);
            }

            // indicate that the parsing has ended
            this._state.End();
        }
    }
}
